home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / libx11 / pstoedit.pro < prev    next >
Text File  |  1999-01-01  |  9KB  |  344 lines

  1. %%Title: pstoedit.pro, Version 2.3.3, November 1995
  2. % This file contains some redefinitions of PostScript(TM) operators
  3. % useful for the conversion of PostScript into a vector format via Ghostscript
  4. %
  5. % Copyright (C) 1993,1994,1995 Wolfgang Glunz, Wolfgang.Glunz@zfe.siemens.de
  6. %
  7. %    This program is free software; you can redistribute it and/or modify
  8. %    it under the terms of the GNU General Public License as published by
  9. %    the Free Software Foundation; either version 2 of the License, or
  10. %    (at your option) any later version.
  11. %
  12. %    This program is distributed in the hope that it will be useful,
  13. %    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. %    GNU General Public License for more details.
  16. %
  17. %    You should have received a copy of the GNU General Public License
  18. %    along with this program; if not, write to the Free Software
  19. %    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. %
  21. %
  22. %%History:
  23. %
  24. % xx.10.95 : fixed calculation of current scale factor
  25. %            added color support
  26. %            escape ( and ) in text for pure PostScript backend
  27. % 08.09.95 : reset rotation angle for non rotated text to 0
  28. % 05.05.95 : Fixed calculation of text angle. Pure text files were not handled correctly. 
  29. %          : Redirect prints from the input PostScript to stderr.
  30. % 27.04.95 : Add support for rotated text (IJMP)
  31. % 24.04.95 : Added some checks for unavailable entries in FontInfo dictionary
  32. % 24.02.95 : some cleanup for version 2.1 (removed unnecessay procs, ...)
  33. % 30.09.94 : fixed some setgray problems (due to grestore)
  34. % 05.05.94 : added support for MIF backend
  35. % 07.09.93 : added widthshow, kshow, awidthshow, showpage
  36. % 28.05.93 : calculate effective line with in setlinewidth
  37. % 22.04.93 : added ashow
  38. % 20.04.93 : fixed a problem in stroke, fill, eofill (use {..} instead of /-... )
  39. %
  40. % 19.04.93 : Version 1.0 released to comp.sources.postscript
  41. %
  42. %%Acknowledgements:
  43. % David B. Rosen <rosen@murmur> for some ideas and some PostScript code 
  44. % from his ps2aplot program.
  45.  
  46. /-print  /print load def
  47. /-fill   /fill load def
  48. /-eofill /eofill load def
  49. /-stroke /stroke load def
  50. /-show   /show load def
  51. /-showpage /showpage load def
  52. /s100 100 string def
  53. /s1000 1000 string def
  54. /onechar 1 string def
  55.  
  56. systemdict begin
  57. /pdfmark { 
  58.     ([ ) -print 
  59.     ] { showpdfmarkelement ( ) -print } forall % close array and dump all entries
  60.     (pdfmark\n) -print 
  61. } def
  62. end
  63.  
  64. /showpdfmarkelement {
  65.     dup type pdftype begin exec end
  66. } def
  67.  
  68. /pdftype 20 dict def
  69. pdftype begin
  70. /arraytype { ([ ) -print { showpdfmarkelement ( ) -print } forall ( ]) -print } def 
  71. /booleantype { s1000 cvs -print } def
  72. /conditiontype { pop } def
  73. /devicetype { pop } def
  74. /dicttype { pop } def
  75. /filetype { pop } def
  76. /fonttype { pop } def
  77. /gstatetype { pop } def
  78. /integertype { s1000 cvs -print } def
  79. /locktype { pop } def
  80. /marktype { pop } def
  81. /nametype { ( /) -print s1000 cvs -print } def
  82. /nulltype { pop } def
  83. /operatortype { pop } def
  84. /packedarraytype { pop } def
  85. /realtype { s1000 cvs -print } def
  86. /savetype { pop } def
  87. /stringtype { (\() -print -print (\)) -print } def
  88. end
  89.  
  90. /pdfmark systemdict /pdfmark get def % overwrite pdfmark in userdict
  91. /currentdistillerparams 1 dict def
  92. currentdistillerparams begin
  93. /CoreDistVersion 2000 def
  94. end
  95.  
  96. /print {
  97.  (\% PRINT ) -print 
  98.  -print
  99.  ( MSG\n) -print
  100. } def
  101.  
  102. /debugprint {
  103. % ( MSG\n) -print % for debugging
  104.  (\n) -print % for normal mode
  105. } def
  106.  
  107. /printTOS {
  108.     ( ) -print s100 cvs -print 
  109. } def
  110.  
  111.  
  112. /prpoints {
  113.     -1 1 { pop        % the loop control variable
  114.        transform  % transform to device coordinates
  115.        exch
  116.        printTOS   % the x value
  117.        deviceheight exch sub % fix flipped y coordinate
  118.        printTOS   % the y value
  119.      } for
  120. } def
  121.  
  122. /getcurrentscale { 
  123. % returns current scale on stack
  124.     100 0 transform % x1' y1'
  125.       /y1 exch def
  126.       /x1 exch def
  127.       0 0 transform % x2' y2'
  128.       /y2 exch def
  129.       /x2 exch def
  130.     x1 x2 sub dup mul 
  131.     y1 y2 sub dup mul 
  132.     add sqrt
  133.     100 div abs
  134. %    dup ( scale is ) -print == (\n) -print
  135. } def
  136.  
  137. /printstate {
  138.     % should be triggerd by (g)restore
  139.     gsave
  140.  
  141.     currentlinewidth
  142.     getcurrentscale mul
  143.     printTOS
  144.     ( setlinewidth \n) -print
  145.  
  146.     currentgray
  147.     printTOS
  148.     ( setgray \n) -print
  149.  
  150.     currentrgbcolor
  151.     3 1 roll exch
  152.     printTOS
  153.     printTOS
  154.     printTOS
  155.     ( setrgbcolor \n) -print
  156.  
  157.     grestore
  158. } def
  159.  
  160. /print-path {
  161.     printstate
  162.     % savely do pathforall
  163.     {
  164.         { 1 prpoints ( moveto\n)    -print }
  165.         { 1 prpoints ( lineto\n)    -print }
  166.         { 3 prpoints ( curveto\n)   -print }
  167.         {            ( closepath\n) -print }
  168.         pathforall
  169.     } stopped {
  170.     } if
  171. } def
  172.  
  173. /dumppath {
  174.     printstate
  175.     /dumpstring exch def
  176.     /dumpop exch def
  177.     (\n) -print
  178.     gsave
  179.     {
  180.         flattenpath % replaces curves by lines
  181.     } stopped {
  182.         grestore
  183.         gsave
  184.     } if
  185.     (newpath \n) -print
  186.     print-path
  187.     dumpstring -print ( \n) -print
  188.     grestore
  189.     dumpop
  190. } def
  191.  
  192. /eofill    {
  193. %     (in pstoedit.pro ) currentgray pstack pop pop
  194.     printstate
  195.     {-eofill} (eofill) dumppath
  196.     } def
  197.  
  198. /fill      {
  199.     printstate
  200.     {-fill} (fill) dumppath
  201.     } def
  202.  
  203. /stroke    {
  204.     printstate
  205.     {-stroke} (stroke) dumppath
  206.     } def
  207.  
  208. /show {
  209.     printstate
  210.     /currentstring exch def
  211.     gsave
  212.     textastext
  213.     {
  214.         % dump text as text  (not as polygon)
  215.         % dump font information (taken from ps2aplot from "David B. Rosen" <rosen@unr.edu> )
  216.  
  217.         % FONTNAME command 
  218.         (/) -print
  219.         currentfont begin
  220.         /FontName where {
  221.             pop FontName s100 cvs % FontName is a name or is already a string
  222.         } {
  223.             (Courier)
  224.         } ifelse -print
  225.         end
  226.         ( findfont ) -print
  227.  
  228.  
  229.         % FONTSIZE command 
  230.         currentfont begin
  231.         FontMatrix 0 get % get the x-scale of the font matrix
  232.         0
  233.         % we have the delta vector dx (original xscale) 0 on the stack
  234.         dtransform
  235.         % now we have dx' and dy' on stack
  236.         % scale is sqrt ( dx' ** 2 + dy' ** 2)
  237.         dup mul exch dup mul add sqrt
  238.         1000 mul % standard fonts have factor of .001 (let's hope)
  239. %        round 
  240.         s100 cvs -print
  241.         end
  242.         ( scalefont setfont\n) -print
  243.  
  244.         % FontFamily, FullName and Weight 
  245.         currentfont begin
  246.         /FontInfo where {
  247.             pop 
  248.             FontInfo begin
  249.             FontInfo /FamilyName known { FamilyName } { (unknown) } ifelse
  250.                 (\% ) -print -print  ( FamilyName \n) -print
  251.             FontInfo /FullName   known { FullName   } { (unknown) } ifelse   
  252.                 (\% ) -print -print  ( FullName \n) -print
  253.             FontInfo /Weight     known { Weight     } { (unknown) } ifelse
  254.                 (\% ) -print -print  ( Weight \n) -print
  255.             end
  256.         } if
  257.         end
  258.  
  259. % debug        1 0 dtransform (\% vector ) -print exch ( x ) -print printTOS ( y ) -print printTOS debugprint
  260.         % Rotation angle
  261.         /pstoeditangle 1 0 dtransform exch atan -1 mul 360 add def
  262. % debug        (\% angle ) -print pstoeditangle printTOS debugprint
  263.         currentpoint /pstoedity exch def /pstoeditx exch def
  264.         pstoeditx pstoedity 1 prpoints ( moveto\n)    -print
  265.         pstoeditangle 360.0 ne {
  266.             pstoeditx pstoedity 1 prpoints ( translate\n) -print
  267.             ( ) -print
  268.             pstoeditangle s100 cvs -print ( rotate\n) -print
  269.         } 
  270.         {
  271.             ( ) -print
  272.             0             s100 cvs -print ( rotate\n) -print
  273.         }
  274.         ifelse
  275.         (\() -print
  276.         escapetext
  277.         {
  278.             % PostScript backend selected, so escape '(' ')' '\'
  279.             currentstring {
  280.             dup (\() 0 get eq { (\\) -print } if
  281.             dup (\)) 0 get eq { (\\) -print } if
  282.             dup (\\) 0 get eq { (\\) -print } if
  283.             % convert integer (from forall) back to string
  284.             % for this put it into the one element string onechar
  285.             % put does not return the modified string, so we have to push it again
  286.             onechar exch 0 exch put onechar -print 
  287.             } forall
  288.         }
  289.         {
  290.             % No need to escape special PostScript characters
  291.             currentstring -print 
  292.         }
  293.         ifelse
  294.  
  295.         (\) show\n) -print
  296.         pstoeditangle 360.0 ne {
  297.             ( ) -print
  298.             pstoeditangle neg s100 cvs -print ( rotate\n) -print
  299.             pstoeditx pstoedity 1 prpoints
  300.             ( ntranslate\n) -print
  301.         } if
  302.     }
  303.     {
  304.         % convert text to polygons
  305.         currentpoint
  306.         /currenty exch def
  307.         /currentx exch def
  308.         stroke % dump current path and start new path
  309.  
  310.         currentx currenty moveto
  311.         currentstring
  312.         true charpath 
  313.         eofill 
  314.     }
  315.     ifelse
  316.     grestore
  317.     currentstring
  318.     -show
  319. } def
  320.  
  321. /widthshow  {exch pop exch pop exch pop show} def
  322. /awidthshow {exch pop exch pop exch pop exch pop exch pop show} def
  323. /kshow      {exch pop show} def
  324. /ashow      {exch pop exch pop show} def
  325.  
  326. /showpage {
  327.     (showpage \n) -print
  328.     -showpage
  329. } def
  330.  
  331. % determine device height
  332. 0 0 transform 
  333. /deviceheight exch def
  334. /devicewidth exch def  % not used so far
  335.  
  336. %300 300 gssetresolution
  337.  
  338. (\%!\n) -print
  339. (\% generated by pstoedit\n) -print
  340. (/ntranslate { neg exch neg exch translate } def\n) -print
  341.  
  342. %/textastext true def
  343. %/escapetext true def
  344.